#pragma once

#include "SystemState.hpp"




namespace Engine
{
	namespace Ui
	{
		/**
		 * The NestedState class implements the same interface as the SystemState class, however
		 * instead of directly containing most of the data, set/get calls are delegated to the
		 * contained state.
		 */
		class NestedState
			: public State
		{
		private:

			const SystemState::ptr   m_state;
			const Cursor             m_cursor;
			int2                     m_parentPos;

		public:

			NestedState(const SystemState::ptr& state);
			NestedState(const NestedState& that, int2 offset);



			/**
			 * Get the cursor.
			 */
			const Cursor& cursor() const;

			/**
			 * Get the parent position.
			 */
			int2 parentPos() const;



			/**
			 * Get the currently active modal widget.
			 * Usually it's the desktop, unless there is another
			 * modal widget.
			 */
			boost::shared_ptr<Widget> modalWidget() const;

			/**
			 * Set the currently active modal widget.
			 */
			void setModalWidget(boost::weak_ptr<Widget> modalWidget);



			/**
			 * Get the current widget with focus.
			 */
			boost::shared_ptr<Widget> focusWidget() const;

			/**
			 * Set the currently active focus widget.
			 */
			void setFocusWidget(boost::weak_ptr<Widget> widget);

			/**
			 * Unset the currently active focus widget.
			 */
			void unsetFocusWidget(boost::weak_ptr<Widget> widget);



			/**
			 * Attach a widgets position to the mouse ones.
			 * As long as the widget is attached to the cursor,
			 * it will move with it.
			 */
			void attach(boost::weak_ptr<Widget> widget);
			void detach(boost::weak_ptr<Widget> widget);
			bool isAttached(boost::weak_ptr<Widget> widget) const;

			/**
			 * Attach a widgets border to the mouse.
			 * This will cause the widget to resize when 
			 * the mouse moves.
			 */
			void attachBorder(boost::weak_ptr<Widget> widget, Border::Type border);
			void detachBorder(boost::weak_ptr<Widget> widget);
			bool isAttachedBorder(boost::weak_ptr<Widget> widget) const;

			/**
			 * Test if anything is attached to the mouse.
			 */
			bool hasAttached() const;
		};
		///////////////////////////////////////////////////////////////////////////////////////////
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////////////////////////////////////
